"Tabs"
set tabstop=4
set softtabstop=4
set shiftwidth=4
set smarttab
set expandtab
au FileType make set noexpandtab tabstop=8 shiftwidth=8 "Switch off for Makefiles"
"Ident"
set autoindent
set cindent
"String wrap"
set wrap

set autoread

set mousehide
set mouse=a

set showmatch
set hlsearch
set incsearch

"Numbers & Syntax"
set nu
sy on

"Status Line"
set laststatus=1 
set statusline=%f%m%r%h%w\ %y\ enc:%{&enc}\ ff:%{&ff}\ fenc:%{&fenc}%=(ch:%3b\ hex:%2B)\ col:%2c\ line:%2l/%L\ [%2p%%]

"Combinations"
"Save -> F2"
imap <F2> <Esc>:wa<cr>
map <F2> <Esc>:wa<cr>
"Save & Exit"
imap <F8> <Esc>:wq<cr>
map <F8> <Esc>:wq<cr>
"Paste file"
imap <F3> <Esc>:read 
map <F3> <Esc>:read 
"Paste from my LIB"
imap <F4> <Esc>:read ~/Work/LIB/
map <F4> <Esc>:read ~/Work/LIB/

"Exit Menu"
set wildmenu
set wcm=<tab>
menu Exit.quit  :quit<cr>
menu Exit.quit! :quit!<cr>
menu Exit.save  :exit<cr>
map <F9> :emenu Exit.<tab>

"Encoding Menu"
set wildmenu
set wcm=<Tab>
menu Encoding.koi8-r  :e ++enc=koi8-r<CR>
menu Encoding.cp1251  :e ++enc=cp1251<CR>
menu Encoding.cp866   :e ++enc=cp866<CR>
menu Encoding.ucs-2le :e ++enc=ucs-2le<CR>
menu Encoding.utf-8   :e ++enc=utf-8<CR>
map <F7> :emenu Encoding.<Tab>

"Completion"
function! InsertTabWrapper(direction)
    let col = col('.') - 1
    if !col || getline('.')[col - 1] !~ '\k'
        return "\<tab>"
    elseif "backwards" == a:direction
        return "\<c-p>"
    else
        return "\<c-n>"
    endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper ("forward")<cr>
inoremap <s-tab> <c-r>=InsertTabWrapper ("backward")<cr>

"Compilation & Interpretation"
"Python"
"<F5> - parse & wait. <F6> - parse & exit"
au FileType python imap <F5> <Esc>:!python -i %<cr>
au FileType python map <F5> <Esc>:!python -i %<cr>
au FileType python imap <F6> <Esc>:!python %<cr>
au FileType python map <F6> <Esc>:!python %<cr>
"C/C++"
"<F5> - compile. <F6> - run"
au FileType c imap <F5> <Esc>:!gcc % -O2 -Wall -Werror -Wformat-security -Wignored-qualifiers -Winit-self -Wswitch-default -Wfloat-equal -Wshadow -Wpointer-arith -Wtype-limits -Wempty-body -Wlogical-op -Wstrict-prototypes -Wold-style-declaration -Wold-style-definition -Wmissing-parameter-type -Wmissing-field-initializers -Wnested-externs -Wno-pointer-sign -std=gnu99 -o 
au FileType c map <F5> <Esc>:!gcc % -O2 -Wall -Werror -Wformat-security -Wignored-qualifiers -Winit-self -Wswitch-default -Wfloat-equal -Wshadow -Wpointer-arith -Wtype-limits -Wempty-body -Wlogical-op -Wstrict-prototypes -Wold-style-declaration -Wold-style-definition -Wmissing-parameter-type -Wmissing-field-initializers -Wnested-externs -Wno-pointer-sign -std=gnu99 -o 
au FileType c imap <F6> <Esc>:!./
au FileType c map <F6> <Esc>:!./

